package hn.cch.netty.api;


import hn.cch.cache.SystemCache;
import hn.cch.common.util.DateUtil;
import hn.cch.common.util.JsonUtil;
import hn.cch.common.util.StringUtil;
import hn.cch.netty.param.EmptyParam;
import hn.cch.netty.request.HttpReqMsg;
import hn.cch.netty.result.ResultClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Date;


@Scope("prototype")
@Component("/http/api/cache")
public class HttpCache implements HttpApi{

    private static Logger logger = LoggerFactory.getLogger(HttpCache.class);

    @Override
    public byte[] api(HttpReqMsg httpReqMsg, byte[] bytes) {



        logger.info("DemoParam : " + StringUtil.fromBytes(bytes));
        // EmptyParam emptyParam = (EmptyParam) JsonUtil.toObject(bytes, EmptyParam.class);

        String time = DateUtil.toText("yyyy-MM-dd HH:mm:ss", new Date());
        SystemCache.setKeyValue("/http/api/cache/time", time);

        ResultClass resultClass = new ResultClass();
        resultClass.setDatetime(time);
        return JsonUtil.toBytes(resultClass);
    }
}